class index {
    constructor() {
        this.index = 0;
        this.lastIndex = 0;
        this.time = null;
        //判断是否登陆
        this.login();
        //给小圆绑定点击播放事件
        this.round();
        //获取轮播图的外侧div,设置鼠标移出,自动轮播的事件
        //设置自动播放事件
        this.autoPlay();
        //跑马灯效果
        this.marquee();
        //倒计时效果
        this.timeSell();
    }
    /* ***判断是否登陆*** */
    login() {
        let id = localStorage.getItem('id');
        let token = localStorage.getItem('token');
        if (!id || !token) {
            location.assign('login.html?comeFrom=index.html');
        }
    }
    /* *****第一个轮播图***** */
    /* ***给小圆按钮绑定点击事件*** */
    round() {
        this.$('.carousel-indicators ol li').forEach((element, indexEl) => {
            // console.log(element);
            element.onclick = () => {
                this.lastIndex = this.index;
                this.index = indexEl;
                this.change();
            }
        });
    }
    /* ***设置自动循环播放*** */
    autoPlay() {
        this.time = setInterval(() => {
            if (this.index == 3) {
                this.lastIndex = 3;
                this.index = 0;
                this.change();
            } else {
                this.lastIndex = this.index;
                this.index++;
                this.change();
            }
            // console.log(this.index,this.lastIndex);
        }, 2000)
    }
    //用于改变的方法
    change() {
        this.$('.carousel-indicators ol li')[this.index].classList.add('ac');
        this.$('.carousel-indicators ol li')[this.lastIndex].classList.remove('ac');
        this.$('.carousel-i ul li')[this.index].classList.add('ac');
        this.$('.carousel-i ul li')[this.lastIndex].classList.remove('ac');
    }
    /* *****第二个轮播图***** */
    //跑马灯效果,不会写,抄来的
    marquee() {
        // console.log(111);
        let speed = 30;
        //速度数值越大速度越慢
        let colee_left2 = this.$('#colee_left2');
        let colee_left1 = this.$('#colee_left1');
        let colee_left = this.$('#colee_left')
        // console.log(colee_left2,colee_left1,colee_left);
        colee_left2.innerHTML = colee_left1.innerHTML;
        function Marquee3() {
            if (colee_left2.offsetWidth - colee_left.scrollLeft <= 0) {//offsetWidth 是对象的可见宽度
                colee_left.scrollLeft -= colee_left1.offsetWidth//scrollWidth 是对象的实际内容的宽，不包边线宽度
            }
            else {
                colee_left.scrollLeft++;
            }
        }
        var MyMar3 = setInterval(Marquee3, speed);
    }
    /* *****倒计时效果***** */
    timeSell() {
        //获取当前时间
        //设置自动获取
        setInterval(() => {
            let timeNow = new Date();
            // console.log(timeNow);
            // console.log(timeNow - 0);
            //设置目标时间
            let timeFuture = new Date('2022.11.11 0:0:0');
            // console.log(timeFuture);
            // console.log(timeFuture - 0);
            //相减获取差值
            let numData = (timeFuture - 0) - (timeNow - 0);
            // console.log(numData);
            let day = parseInt(numData / 1000 / 60 / 60 / 24);
            let hour = parseInt(numData / 1000 / 60 / 60 % 24);
            let minute = parseInt(numData / 1000 / 60 % 60);
            let second = parseInt(numData / 1000 % 60);
            // console.log(day, hour, minute, second);
            //获取节点
            //判断位数
            console.log(day.toString().length);
            this.$('.day').innerHTML=day.toString().length==2?day+'天':'0'+day+'天';
            this.$('.hour').innerHTML=hour.toString().length==2?hour:'0'+hour;
            this.$('.minute').innerHTML=minute.toString().length==2?minute:'0'+minute;
            this.$('.second').innerHTML=second.toString().length==2?second:'0'+second;
        }, 1000)


    }
    /* 自制的获取节点 */
    $(ele) {
        let element = document.querySelectorAll(ele);
        return element.length == 1 ? element[0] : element;
    }
}
new index;